/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * usuarios_alterar_senha.java
 *
 * Created on 28/05/2011, 14:17:15
 */
package Visualização;

import javax.swing.JOptionPane;

/**
 *
 * @author Fabio
 */
public class usuarios_alterar_senha extends javax.swing.JFrame {
        String usuario;
    /** Creates new form usuarios_alterar_senha */
    public usuarios_alterar_senha(BO.usuarioBO uBO) {
        initComponents();
        this.setLocationRelativeTo(null);
        usuario = uBO.getLoginBO();
    }

    private usuarios_alterar_senha() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        bt_cancelar = new javax.swing.JButton();
        bt_gravar = new javax.swing.JButton();
        confirmaSenhaInput = new javax.swing.JPasswordField();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        novaSenhaInput = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel1.setText("Alteração de Senha");

        bt_cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Cancelar.png"))); // NOI18N
        bt_cancelar.setText("Cancelar");
        bt_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_cancelarActionPerformed(evt);
            }
        });

        bt_gravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Salvar.png"))); // NOI18N
        bt_gravar.setText("Gravar");
        bt_gravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_gravarActionPerformed(evt);
            }
        });

        confirmaSenhaInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmaSenhaInputActionPerformed(evt);
            }
        });

        jLabel5.setText("Confirmar Senha:");

        jLabel4.setText("Nova Senha:");

        novaSenhaInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novaSenhaInputActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(bt_gravar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_cancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4))
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(novaSenhaInput, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                            .addComponent(confirmaSenhaInput, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)))
                    .addComponent(jLabel1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(novaSenhaInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(confirmaSenhaInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_gravar)
                    .addComponent(bt_cancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_cancelarActionPerformed
        this.dispose();
}//GEN-LAST:event_bt_cancelarActionPerformed

    private void bt_gravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_gravarActionPerformed
        if (verificar()==1)
        {
            BO.usuarioBO uBO = new BO.usuarioBO();
            Negocio.usuario u = new Negocio.usuario();

            uBO.setLoginBO(usuario);
            uBO.setSenhaBO(novaSenhaInput.getText());
            u.admAlterarSenha(uBO);
            JOptionPane.showMessageDialog(rootPane, "Senha alterada com sucesso!");
            novaSenhaInput.setText("");
            confirmaSenhaInput.setText("");
        }  
}//GEN-LAST:event_bt_gravarActionPerformed

    private void confirmaSenhaInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmaSenhaInputActionPerformed
        bt_gravarActionPerformed(evt);
}//GEN-LAST:event_confirmaSenhaInputActionPerformed

    private void novaSenhaInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novaSenhaInputActionPerformed
        bt_gravarActionPerformed(evt);
}//GEN-LAST:event_novaSenhaInputActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new usuarios_alterar_senha().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_cancelar;
    private javax.swing.JButton bt_gravar;
    private javax.swing.JPasswordField confirmaSenhaInput;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPasswordField novaSenhaInput;
    // End of variables declaration//GEN-END:variables
    public int verificar(){
        if(novaSenhaInput.getText().equals(""))
        {
            JOptionPane.showMessageDialog(rootPane, "Digite um nova senha");
            return 0;
        }
        else if(novaSenhaInput.getText().length()<6)
        {
            JOptionPane.showMessageDialog(rootPane, "Sua senha deve ter no minimo 6 dígitos!");
            return 0;
        }
        else if(!novaSenhaInput.getText().equals(confirmaSenhaInput.getText()))
        {
            JOptionPane.showMessageDialog(rootPane, "Os campos devem ser iguais!");
            return 0;
        }
        else
            return 1;
    }
}
